home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Online / NNTPd / server / group.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-03  |  4.0 KB  |  193 lines

  1. #ifndef lint
  2. static char    sccsid[] = "@(#)group.c    1.12    (Berkeley) 5/11/89";
  3. #endif
  4.  
  5. #include "common.h"
  6.  
  7. #ifdef XTHREAD
  8. extern char *thread_name();
  9. #endif
  10. #if defined(XOVER) || defined(XROVER)
  11. extern void close_xfiles();
  12. #endif
  13.  
  14. extern char *malloc();
  15.  
  16. /*
  17.  * GROUP newsgroup
  18.  *
  19.  * Change the current group to the specified newsgroup.
  20.  * We also change our current directory to that newsgroup if
  21.  * a spool directory for it exists.
  22.  * If the newsgroup specified is invalid, the old newsgroup
  23.  * remains selected.
  24.  */
  25.  
  26. void
  27. group(argc, argv)
  28.     int    argc;
  29.     char    *argv[];
  30. {
  31.     char    temp_dir[256];
  32.     int    high_msg, low_msg;
  33.     char    *cp;
  34.     char    *reqlist[2];
  35.  
  36.     if (argc != 2) {
  37.         printf("%d Usage: GROUP newsgroup.\r\n", ERR_CMDSYN);
  38.         (void) fflush(stdout);
  39.         return;
  40.     }
  41.  
  42.     if (!canread) {
  43.         printf("%d You only have permission to transfer, sorry.\r\n",
  44.             ERR_ACCESS);
  45.         (void) fflush(stdout);
  46.         return;
  47.     }
  48.  
  49.     if (index(argv[1], '/') != (char *) NULL) {
  50.         printf("%d Invalid group name (bad format).\r\n", ERR_NOGROUP);
  51.         (void) fflush(stdout);
  52.         return;
  53.     }
  54.  
  55.     if (find_group(argv[1], &low_msg, &high_msg) < 0) {
  56.         printf("%d Invalid group name (not in active).\r\n",
  57.             ERR_NOGROUP);
  58.         (void) fflush(stdout);
  59.         return;
  60.     }
  61.  
  62.     reqlist[0] = argv[1];
  63.     reqlist[1] = NULL;
  64.  
  65.     if (ngpermcount) {
  66.         if (ngmatch(s1strneql, ALLBUT,
  67.             ngpermlist, ngpermcount, reqlist, 1) == 0) {
  68.             printf("%d You're not allowed to read %s, sorry.\r\n",
  69.                 ERR_ACCESS, argv[1]);
  70.             (void) fflush(stdout);
  71.             return;
  72.         }
  73.     } else if (ALLBUT == 0) {
  74.         printf("%d You're not allowed to read %s, sorry.\r\n",
  75.             ERR_ACCESS, argv[1]);
  76.         (void) fflush(stdout);
  77.         return;
  78.     }
  79.  
  80. #if defined(XOVER) || defined(XROVER)
  81.     close_xfiles();
  82. #endif
  83.     close_crnt();
  84.     if (group_name)
  85.         free(group_name);
  86.     (void) chdir(spooldir);
  87.     if ((group_name = malloc(strlen(argv[1])+1)) != NULL)
  88.         strcpy(group_name, argv[1]);
  89.  
  90. #ifdef LOG
  91.     syslog(LOG_INFO, "%s group %s", hostname, argv[1]);
  92. #endif
  93.  
  94.     while ((cp = index(argv[1], '.')) != (char *) NULL)
  95.         *cp = '/';
  96.  
  97.     (void) strcpy(temp_dir, spooldir);
  98.     (void) strcat(temp_dir, "/");
  99.     (void) strcat(temp_dir, argv[1]);
  100.  
  101.     /*
  102.      * (void) because a group can be in the active file
  103.      * but not have a spool directory.  Just leave us
  104.      * chdired to base spool directory if this fails.
  105.      */
  106.     (void) chdir(temp_dir);
  107.  
  108. #ifdef LOG
  109.     ++grps_acsd;
  110. #endif
  111.  
  112.     num_arts = scan_dir(low_msg, high_msg);
  113.     art_ptr = 0;
  114.  
  115.     ingroup = 1;
  116.  
  117. #ifdef    XTHREAD
  118.     threadfile = thread_name(argv[1]);
  119. #endif
  120.  
  121.     while ((cp = index(argv[1], '/')) != (char *) NULL)
  122.         *cp = '.';
  123.  
  124.     printf("%d %d %d %d %s\r\n",
  125.         OK_GROUP,
  126.         num_arts,
  127.         (num_arts > 0 ? art_array[0] : 0),
  128.         (num_arts > 0 ? art_array[num_arts-1] : 0),
  129.         argv[1]);
  130.     (void) fflush(stdout);
  131. }
  132.  
  133. #ifdef LISTGROUP
  134. /*
  135.  * LISTGROUP [group]
  136.  *
  137.  * Lists all article numbers (filenames) in the given group. Used by
  138.  * newsreaders such as nn and trn for fast validation of a database.
  139.  * If a group name is given it becomes the current group.
  140.  *
  141.  * This command is an extension, and not included in RFC 977.
  142.  */
  143.  
  144. void
  145. xlistgroup(argc, argv)
  146.     int        argc;
  147.     char        *argv[];
  148. {
  149.     register int i;
  150.  
  151.     if (argc == 2) {
  152.         ingroup = 0;
  153.         /* This will output a success or failure message */
  154.         group(argc, argv);
  155.         if (!ingroup) {
  156.             return;
  157.         }
  158.     } else if (argc > 2) {
  159.         printf("%d Usage: LISTGROUP [newsgroup].\r\n", ERR_CMDSYN);
  160.         (void) fflush(stdout);
  161.         return;
  162.     } else if (!ingroup) {
  163.         printf("%d You are not currently in a newsgroup.\r\n",
  164.             ERR_NCING);
  165.         (void) fflush(stdout);
  166.         return;
  167.     } else if (!canread) {
  168.         printf("%d You only have permission to transfer, sorry.\r\n",
  169.             ERR_ACCESS);
  170.         (void) fflush(stdout);
  171.         return;
  172.     } else {
  173.         /* output a success message when no group name is given */
  174.         printf("%d %d %d %d %s\r\n",
  175.             OK_GROUP,
  176.             num_arts,
  177.             (num_arts > 0 ? art_array[0] : 0),
  178.             (num_arts > 0 ? art_array[num_arts-1] : 0),
  179.             group_name? group_name : "(current group)");
  180.     }
  181.  
  182. #ifdef LOG
  183.     syslog(LOG_INFO, "%s listgroup", hostname);
  184. #endif
  185.     for (i = 0; i < num_arts; i++) {
  186.         printf("%d\r\n", art_array[i]);
  187.     }
  188.     putline(".");
  189.     (void) fflush(stdout);
  190. }
  191.  
  192. #endif /* LISTGROUP */
  193.